﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinForm_Mes.Common.Models.Warehouse;
using WinForm_Mes.Common.PublicFields;
namespace WinForm_Mes.WarehouseManagement
{
    public partial class WarehouseAddForm : DevExpress.XtraEditors.XtraForm
    {
        public delegate void WarehouseAddedHandler();
        public event WarehouseAddedHandler WarehouseAdded;
        public WarehouseAddForm(string newOrderNumber)
        {
            InitializeComponent();
            labelControl8.Text = newOrderNumber; // 绑定新仓库编号
        }

        //保存单击事件
        private async void simpleButton1_Click(object sender, EventArgs e)
        {
            WarehouseModel model = new WarehouseModel
            {
                WarehouseCode = labelControl8.Text.Trim(),
                WarehouseName = textEdit1.Text.Trim(),
                WarehouseAddress = textEdit2.Text.Trim(),
                WarehouseArea = textEdit5.Text.Trim(),
                ResponsiblePerson = textEdit4.Text.Trim(),
                Remark = textEdit3.Text.Trim()

            };

            var response = await PublicFields.client.PostAsJsonAsync("http://localhost:5113/api/Warehouse/AddWarehouse", model);
            if (response.IsSuccessStatusCode)
            {
                // 调用委托，通知父窗体刷新
                WarehouseAdded?.Invoke();
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败：" + response.StatusCode);
            }
        }

        private void WarehouseAddForm_Load(object sender, EventArgs e)
        {

        }
    }
}